home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inter.Net 55-2
/
Inter.Net 55-2.iso
/
Mandrake
/
misc
/
build_archive
next >
Wrap
Text File
|
2000-01-12
|
2KB
|
64 lines
#!/usr/bin/perl
#- Simple cat archive with bzip2 for perl.
#- read file list and produce a perl script in stdout with hash data and $ARGV[0].cz2 archive file.
#- hash data is :
#- { 'filename' => [ $off1, $siz1, $off2, $siz2 ], ... }
#- bzip2 -d between ..1 and ..2
use strict qw(subs vars refs);
sub main {
my ($name, $maxsiz) = @_;
my ($off1, $siz1, $off2, $siz2) = (0, 0, 0, 0);
my @filelist = ();
my %data = ();
die "usage: $0 <name> <maxsiz>" unless $maxsiz > 100000;
unlink "$name.cz2";
foreach (<STDIN>) {
chomp;
my $file = $_; die "unable to find file $file" unless -e $file;
$siz2 = -s $file;
push @filelist, $file;
$data{$file} = [ -1, -1, $off2, $siz2 ];
if ($off2 + $siz2 > $maxsiz) { #- need compression.
system "cat @filelist | bzip2 -3 >tmp.bz2";
$siz1 = -s "tmp.bz2";
$data{$_} = [ $off1, $siz1, $data{$_}[2], $data{$_}[3] ] foreach @filelist;
system "cat tmp.bz2 >>$name.cz2";
$off1 += $siz1;
$off2 = 0; $siz2 = 0;
@filelist = ();
}
$off2 += $siz2;
}
if (scalar @filelist) {
system "cat @filelist | bzip2 -3 >tmp.bz2";
$siz1 = -s "tmp.bz2";
$data{$_} = [ $off1, $siz1, $data{$_}[2], $data{$_}[3] ] foreach @filelist;
system "cat tmp.bz2 >>$name.cz2";
$off1 += $siz1;
print STDERR "archive size of $name.cz2 is $off1\n";
}
local *OUTPUT;
open OUTPUT, ">$name.cz2.pl";
print OUTPUT "\%data = (\n";
foreach (keys %data) {
print OUTPUT "\'$_\' => [ ". join(', ', @{$data{$_}}) ." ],\n";
}
print OUTPUT ");\n";
}
main(@ARGV);
unlink "tmp.bz2";